#-*- coding:utf8 -*-
from django.db import models

import unittest
import datetime
from django.contrib.auth.models import User
from master.models import UserProfiles
from master.models import Companies

import logging
logger = logging.getLogger(__name__)


class Projects(models.Model):
    company = models.ForeignKey(Companies)
    
    code = models.CharField(max_length=32)
    name = models.CharField(max_length=200)
    description = models.CharField(max_length=2000, blank=True, null=True)
    
    start_date = models.DateField(blank=True, null=True)
    end_date = models.DateField(default='9999-12-31')
    
    up_project = models.ForeignKey('self', null=True)
    
    
    cdate = models.DateField(blank=True, null=True, default=datetime.date.today())
    udate = models.DateField(blank=True, null=True, default=datetime.date.today())
    ddate = models.DateField(blank=True, null=True)

    class Meta:
        unique_together = ("company", "code",)

    def __unicode__(self):
        return "Projects..."
    
    

class UserProjects(models.Model):
    project = models.ForeignKey(Projects)
    user = models.ForeignKey(User)
    
    
    cdate = models.DateField(blank=True, null=True, default=datetime.date.today())
    udate = models.DateField(blank=True, null=True, default=datetime.date.today())
    ddate = models.DateField(blank=True, null=True)

    class Meta:
        unique_together = ("project", "user",)

    def __unicode__(self):
        return "UserProjects..."


class Worksheets(models.Model):
    userProject = models.OneToOneField(UserProjects)
    
    date = models.DateField()
    work_time = models.SmallIntegerField(blank=True, null=True, default=0)
    over_work_time = models.SmallIntegerField(blank=True, null=True, default=0)
    memo = models.TextField(blank=True, null=True)
    
    
    cdate = models.DateField(blank=True, null=True, default=datetime.date.today())
    udate = models.DateField(blank=True, null=True, default=datetime.date.today())
    ddate = models.DateField(blank=True, null=True)
    
    
    class Meta:
        unique_together = ('userProject', 'date')
        
    def __unicode__(self):
        return "WorkSheets..."
    
    
    
    
